PREFIX?=/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/image/opt/Qtopia

define BUILD
@+QPEDIR=`cd $(QPEDIR); /bin/pwd`;\
outpath=`cd /home/jnussas/NDS/qtopia-free-2.2.0/qtopia; /bin/pwd`;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    grep 'CONFIG.*buildQtopia\b' $$QPEDIR/src/config.pri >/dev/null 2>&1 && QTOPIADESKTOP=0;\
fi;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    grep 'CONFIG.*buildQtopiadesktop\b' $$QPEDIR/src/config.pri >/dev/null 2>&1 || QTOPIADESKTOP=0;\
fi;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    shadowdir=`echo $$PWD | perl -ne 's,'$$QPEDIR'/src/applications,'$$QPEDIR'/src/qtopiadesktop,;\
					s,'$$QPEDIR'/src/libraries/([^\d]+)\d?,'$$QPEDIR'/src/qtopiadesktop/libraries/$$1,;\
					print'`;\
    if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	cd "$$shadowdir";\
	$(MAKE) $@;\
    else\
	shadowdir=`echo $$PWD | perl -ne 's,'$$outpath'/src/applications,'$$QPEDIR'/src/qtopiadesktop,;\
					    s,'$$outpath'/src/libraries/([^\d]+)\d?,'$$QPEDIR'/src/qtopiadesktop/libraries/$$1,;\
					    print'`;\
	if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	    cd "$$shadowdir";\
	    $(MAKE) $@;\
	else\
	    QTOPIADESKTOP=0;\
	fi;\
    fi;\
fi;\
if [ "$$QTOPIADESKTOP" != 1 ]; then\
    if [ "$$QPEDIR" = "$$outpath" ]; then\
	$(MAKE) -f Makefile.target $@ INSTALL_ROOT=$(PREFIX);\
    else \
	shadowdir=`echo $$PWD | perl -ne 's,'$$outpath','$$QPEDIR',;print'`;\
	if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	    cd "$$shadowdir";\
	    $(MAKE) -f Makefile $@ INSTALL_ROOT=$(PREFIX);\
	else\
	    echo "ERROR: Trying to shadow hop but PWD is outside the Qtopia source tree.";\
	    echo "       OUTPATH='$$outpath'";\
	    echo "       QPEDIR='$$QPEDIR'";\
	    echo "       PWD='$$PWD'";\
	    exit 1;\
	fi;\
    fi;\
fi
endef

define QMAKE_BUILD
@+QPEDIR=`cd $(QPEDIR); /bin/pwd`;\
outpath=`cd /home/jnussas/NDS/qtopia-free-2.2.0/qtopia; /bin/pwd`;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    grep 'CONFIG.*buildQtopia\b' $$QPEDIR/src/config.pri >/dev/null 2>&1 && QTOPIADESKTOP=0;\
fi;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    grep 'CONFIG.*buildQtopiadesktop\b' $$QPEDIR/src/config.pri >/dev/null 2>&1 || QTOPIADESKTOP=0;\
fi;\
if [ "$$QTOPIADESKTOP" = 1 ]; then\
    shadowdir=`echo $$PWD | perl -ne 's,'$$QPEDIR'/src/applications,'$$QPEDIR'/src/qtopiadesktop,;\
					s,'$$QPEDIR'/src/libraries/([^\d]+)\d?,'$$QPEDIR'/src/qtopiadesktop/libraries/$$1,;\
					print'`;\
    if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	cd "$$shadowdir";\
	$(MAKE) $@;\
    else\
	shadowdir=`echo $$PWD | perl -ne 's,'$$outpath'/src/applications,'$$QPEDIR'/src/qtopiadesktop,;\
					    s,'$$outpath'/src/libraries/([^\d]+)\d?,'$$QPEDIR'/src/qtopiadesktop/libraries/$$1,;\
					    print'`;\
	if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	    cd "$$shadowdir";\
	    $(MAKE) $@;\
	else\
	    QTOPIADESKTOP=0;\
	fi;\
    fi;\
fi;\
if [ "$$QTOPIADESKTOP" != 1 ]; then\
    if [ "$$QPEDIR" = "$$outpath" ]; then\
	$(MAKE) -f Makefile.target -n $@ INSTALL_ROOT=$(PREFIX) >/dev/null 2>&1 || exec $(MAKE) regenerate; $(MAKE) -f Makefile.target $@ INSTALL_ROOT=$(PREFIX);\
    else \
	shadowdir=`echo $$PWD | perl -ne 's,'$$outpath','$$QPEDIR',;print'`;\
	if [ "$$shadowdir" != "$$PWD" -a -d "$$shadowdir" ]; then\
	    cd "$$shadowdir";\
	    $(MAKE) -f Makefile -n $@ INSTALL_ROOT=$(PREFIX) >/dev/null 2>&1 || exec $(MAKE) regenerate; $(MAKE) -f Makefile $@ INSTALL_ROOT=$(PREFIX);\
	else\
	    echo "ERROR: Trying to shadow hop but PWD is outside the Qtopia source tree.";\
	    echo "       OUTPATH='$$outpath'";\
	    echo "       QPEDIR='$$QPEDIR'";\
	    echo "       PWD='$$PWD'";\
	    exit 1;\
	fi;\
    fi;\
fi
endef

all:
	$(BUILD)
distclean:
	$(BUILD)
clean:
	$(BUILD)
install:
	$(BUILD)
install_target:
	$(BUILD)
uninstall:
	$(BUILD)
packages:
	$(BUILD)
lupdate:
	$(BUILD)
sdk:
	$(BUILD)
devsdk:
	$(BUILD)
remove_target:
	$(BUILD)
relink:
	$(BUILD)
first:
	$(BUILD)
qmake_all:
	$(BUILD)
uicables:
	$(BUILD)
mocables:
	$(BUILD)
uiclean:
	$(BUILD)
mocclean:
	$(BUILD)
lexclean:
	$(BUILD)
yaccclean:
	$(BUILD)
uninstall_subdirs:
	$(BUILD)
install_subdirs:
	$(BUILD)
FORCE:
	$(BUILD)
qmake:
	$(QMAKE_BUILD)

qmake-debug:
	/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/bin/qmake -d -o Makefile.target -spec /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/mkspecs/qws/linux-generic-g++ /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/themes.pro

regenerate:
	/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/bin/qmake  -o Makefile.target -spec /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/mkspecs/qws/linux-generic-g++ /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/themes.pro
	echo Re-creating /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/Makefile
	@/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/configure --makemakefile "/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/Makefile" "/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/Makefile.target" "0" "/home/jnussas/NDS/qtopia-free-2.2.0/qtopia/bin/qmake  -o Makefile.target -spec /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/mkspecs/qws/linux-generic-g++ /home/jnussas/NDS/qtopia-free-2.2.0/qtopia/etc/themes/themes.pro"

.PHONY: all distclean clean install install_target uninstall packages lupdate sdk devsdk remove_target relink first qmake_all uicables mocables uiclean mocclean lexclean yaccclean uninstall_subdirs install_subdirs FORCE qmake-debug regenerate
